# -*- coding:utf-8 -*-

# Author: json_steve


from flask import Flask, current_app, make_response, request, session

app = Flask(__name__)

app.secret_key = '123'


@app.route('/')
def index():
    response = make_response('jsonsteve')

    # response.headers['Set-Cookie'] = 'heads'

    response.set_cookie('a', '1', max_age=3600)

    return response


@app.route('/get_cookie')
def get_cookie():
    print
    request.cookies  # {'heads; a': u'1'}

    # k = request.cookies['heads; a']   # cookie的获取


    k = request.cookies['a']  # 获取不到　报错

    print(k)

    return 'get_cookie %s' % k


@app.route('/delete_cookie')
def delete_cookie():
    response = make_response('delete_success')

    response.delete_cookie('a')

    return response


@app.route('/set_session')
def set_session():
    session['name'] = 'jsonsteve'  # 设置sesssion

    return 'set_success'


@app.route('/get_session')
def get_session():
    name = session.get('name')  # 获取session 存哪里去了

    return name


if __name__ == '__main__':
    app.run(debug=True)